package tech.lq0.dreamaticdelight.item.food.misc;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import vectorwing.farmersdelight.common.item.ConsumableItem;

import java.util.List;

public class CarnivalMeal extends ConsumableItem {

    private static final FoodProperties FOOD = (new FoodProperties.Builder()).nutrition(20).saturationMod(0.5F)
            .effect(() -> new MobEffectInstance(MobEffects.HUNGER, 1800, 4), 1.0F)
            .effect(() -> new MobEffectInstance(MobEffects.DARKNESS, 1800, 0), 1.0F)
            .effect(() -> new MobEffectInstance(MobEffects.BLINDNESS, 1800, 0), 1.0F)
            .effect(() -> new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 1800, 0), 1.0F)
            .effect(() -> new MobEffectInstance(MobEffects.DIG_SLOWDOWN, 1800, 0), 1.0F)
            .effect(() -> new MobEffectInstance(MobEffects.CONFUSION, 1800, 0), 1.0F)
            .effect(() -> new MobEffectInstance(MobEffects.WEAKNESS, 1800, 0), 1.0F)
            .effect(() -> new MobEffectInstance(MobEffects.POISON, 1800, 0), 1.0F)
            .alwaysEat().build();

    public CarnivalMeal() {
        super(new Properties().food(FOOD).craftRemainder(Items.BUCKET).stacksTo(1).rarity(Rarity.UNCOMMON), true);
    }

    @Override
    public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag isAdvanced) {
        tooltip.add(Component.translatable("des.dreamaticdelight.carnival_meal").withStyle(ChatFormatting.GRAY));
        super.appendHoverText(stack, level, tooltip, isAdvanced);
    }

    @Override
    public ItemStack finishUsingItem(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity) {
        if (!pLevel.isClientSide) {
            if (pLivingEntity instanceof Player player) {
                player.getFoodData().eat(-40, 0.5f);
            }
        }

        return super.finishUsingItem(pStack, pLevel, pLivingEntity);
    }
}
